package org.wk.user.service;

import org.apache.http.HttpRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wk.core.common.view.ResponseVo;
import org.wk.core.db.tool.WebUtils;
import org.wk.user.dao.UserDao;
import org.wk.user.domain.User;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Service
public class PromoteServiceImpl implements PromoteService{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserDao userDao;

    @Autowired
    private HttpServletRequest httpRequest;

    /**
     * 获取分享信息
     *
     * @return
     */
    @Override
    public ResponseVo shareInfo() {
        String userId = WebUtils.getUser().getId();
        User user = userDao.getOne(userId);
        logger.info("请求地址========{}",httpRequest.getRequestURL().toString());
        String requestUrl = httpRequest.getRequestURL().toString();
        requestUrl = requestUrl.replaceAll("shareinfo","referral_code?referralCode="+user.getMobileNumber());
        Map<String,String> resData = new HashMap<>(4);
        resData.put("share_title","欢迎注册鲸拍");
        resData.put("share_image","http://img.qiniu.vp359.com/share-logo.png");
        resData.put("share_desc","鲸拍，国内第一家（也可能是全世界第一家）有趣、好玩、省钱、赚钱的商品在线竞拍平台。");
        resData.put("share_link",requestUrl);

        return ResponseVo.success().setData(resData);
    }
}
